<?php

namespace app\index\model;

use think\Model;

class Article extends Model
{
    protected $dateFormat = false;

    /**
     * 获取所有针对文章的评论。
     */
    public function messages(){
        return $this->morphMany('Message','messagetable',1);
    }


    public static function read($id = 0,$page = 1,$limit=1){

        $rel = self::get($id);
        $data =$rel->toArray();

        //多态关联分页查询
        $data['messages'] = $rel->messages()->order('id', 'desc')->paginate($limit, FALSE, [
            'page' => $page,
        ])->toArray();


//        halt($data);

        return $data;
    }
}
